#pragma once

#include <QWidget>
#include "ui_QRSExpressionWidget.h"

class MainWindow;
class ExpressionManager;
class QTableWidgetItem;
class Expression;

QT_BEGIN_NAMESPACE
namespace Ui { class QRSExpressionWidgetClass; };
QT_END_NAMESPACE

class QRSExpressionWidget : public QWidget
{
public:
	QRSExpressionWidget(MainWindow* inMainWindow, QWidget *parent = nullptr);
	~QRSExpressionWidget();

protected:
	virtual void closeEvent(QCloseEvent* event) override;
	void onTableWidgetItemClicked(QTableWidgetItem* item);
	void onModifyExpression();
	void onAddExpression();
    void onDeleteExpression();

private:
	Ui::QRSExpressionWidgetClass *ui;

    ExpressionManager* m_expressionManager;
	MainWindow* m_mainWindow;

	bool bIsConfirmed = false;

	std::pair<int, int> m_selectedItem = { -1,-1 };
	// row -> expression
	QHash<int, std::shared_ptr<Expression>> m_expressions;
	// row -> 表达式计算的结果
    // QHash<int, float> m_expressionResults;
	// 缓存被删除expression的行index
	std::vector<int> m_deleteExpressionIndex;
};
